package com.miao.elm.controller;

import com.miao.elm.entity.BusinessEntity;
import com.miao.elm.service.BusinessService;
import com.miao.elm.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
//@RefreshScope
@RequestMapping("BusinessController")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @PostMapping("/listBusinessByOrderTypeId")
    public List<BusinessEntity> listBusinessByOrderTypeId(@RequestParam int orderTypeId){
        return businessService.listBusinessByOrderTypeId(orderTypeId);
    }

    @RequestMapping("/getBusinessById")
    public BusinessEntity getBusinessById(@RequestParam("businessId") int businessId){
        return businessService.getBusinessById(businessId);
    }



    @RequestMapping("/info/{businessId}")
    public R info(@PathVariable("businessId") Integer businessId){
		BusinessEntity business = businessService.getById(businessId);

        return R.ok().put("business", business);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BusinessEntity business){
		businessService.save(business);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BusinessEntity business){
		businessService.updateById(business);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] businessIds){
		businessService.removeByIds(Arrays.asList(businessIds));

        return R.ok();
    }

}
